Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(shareReplay): don't restart when refCount if the source has completed #5457

Merged
merged 2 commits into from
May 27, 2020

Conversation

josepot
Copy link
Contributor

@josepot josepot commented May 26, 2020

Description:
As discussed in #5455: it would be useful to have a test that removes the ambiguity on what should happen with the shareReplay operator if refCount is true once the source completes.

I've also added a second commit that gets rid of the redundant variable isComplete. This variable became unnecessary after this change. I guess that this second commit is a "nit pick", so I don't mind removing it from this PR. Although, it may marginally reduce the bundle size?

Related issue
#5455

Copy link
Collaborator

@cartant cartant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. This LTGM. I'm happy with the code change, but I think the test needs another expectation.

const shared = source.pipe(shareReplay({ bufferSize: 1, refCount: true }));

expectObservable(shared, sub1).toBe(expected1);
expectObservable(shared, sub2).toBe(expected2);
Copy link
Collaborator

@cartant cartant May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to test that there is only one subscription to the source. That can be done with expectSubscriptions which takes an expected subscription marble diagram - or an array of diagrams if multiple subscriptions are expected.

Something like this:

    const source     = cold('a-(b|)         ');
    const sourceSubs =      '^-!            ';
    /* ... */
    expectSubscriptions(source.subscriptions).toBe(sourceSubs);

If multiple subscriptions to the source are made, this expectation would fail, as sourceSubs would have to be an array of subscriptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. That makes a lot of sense. I've amended that commit with this expectation, thanks!

I've also added another commit that does the same thing on other tests that were not doing that. I do understand that for those tests that expectation may not be as important, because the current expectations are "implicitly" checking for that already. So, I don't mind dropping this commit from the PR. I thought that maybe for consistency it could be worth it to have those expectations?

@josepot josepot force-pushed the test/sharereplay-refcount branch 2 times, most recently from 13fcd67 to 2863c9d Compare May 26, 2020 09:26
@josepot josepot requested a review from cartant May 26, 2020 09:36
Copy link
Collaborator

@cartant cartant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The code change - the removal of the unnecessary isComplete - looks fine to me, but I'll leave merging this until @benlesh has had a look at it. Thanks for the PR.

@benlesh
Copy link
Member

benlesh commented May 27, 2020

What's not immediately clear to me from this PR is whether or not this is a breaking change. It doesn't look like it is, but the only way to know that for sure would have been to land the passing test, then land the change proving it didn't break the test.

@cartant
Copy link
Collaborator

cartant commented May 27, 2020

@benlesh There should be no behavioural changes in this whatsoever. The PR adds a test that describes behaviour that was not fully characterised by the docs. Namely that the completion should be replayed regardless of the refCount option. The removal of the unnecessary isComplete is an incidental clean up, so to speak.

The original PR - which was closed - sought to change the behaviour.

@cartant
Copy link
Collaborator

cartant commented May 27, 2020

@josepot Maybe you should remove the commit that removes the isComplete variable from this PR and then open another with that change?

@josepot josepot force-pushed the test/sharereplay-refcount branch from 2863c9d to f771c8b Compare May 27, 2020 06:50
@cartant cartant merged commit e1d8da9 into ReactiveX:master May 27, 2020
@josepot
Copy link
Contributor Author

josepot commented May 27, 2020

Yep, no worries. I've dropped the commit that removes the isComplete variable. @benlesh has a point, for sure. I mean, if I had a way to run the CI on the first and the last commit, then I guess that it would have been ok to squish the commit that removed the isComplete varialbe in the middle

@cartant
Copy link
Collaborator

cartant commented May 27, 2020

@benlesh I merged this, as the code modification - the removal of the unnecessary variable - was removed, so this PR now only adds a test and some some additional expectations.

@cartant
Copy link
Collaborator

cartant commented May 27, 2020

@josepot Feel free to open another PR that removes that unnecessary variable. If it's not needed and the code's simpler without it, it might as well be deleted.

@josepot josepot deleted the test/sharereplay-refcount branch May 27, 2020 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants